package com.fate.controller;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.fate.es.ProdEs;

import com.fate.service.SearchService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping
@Api(tags = "搜索接口管理")
public class SearchController {
    @Autowired
    private SearchService searchService;

    @GetMapping("prod/prodListByTagId")
    @ApiOperation("根据分组标签id分页查询商品信息")
    public ResponseEntity<Page<ProdEs>> findProdEsByTagId(@RequestParam(required = false, defaultValue = "0") Integer page,
                                                          Integer size,
                                                          Long tagId){
        Page<ProdEs> prodEsPage = searchService.findProdEsByTagId(page, size, tagId);
        return ResponseEntity.ok(prodEsPage);
    }

    @GetMapping("search/searchProdPage")
    @ApiOperation("根据关键字分页排序高亮查询商品信息")
    public ResponseEntity<Page<ProdEs>> searchProdPage(@RequestParam(required = false, defaultValue = "0") Integer current,
                                                       Integer size,
                                                       String prodName,
                                                       Integer sort) {
        Page<ProdEs> prodEsPage = searchService.findProdEsByKeyword(current, size, prodName, sort);
        return ResponseEntity.ok(prodEsPage);
    }

    /**
     * 提供远程调用搜索服务根据ids搜索商品
     *
     * @param prodIds
     * @return
     */
    @PostMapping("/search/getProdEsByIds")
    @ApiOperation("提供远程调用搜索服务根据ids搜索商品")
    List<ProdEs> getProdEsByIds(@RequestBody List<Long> prodIds) {
        return searchService.getProdEsByIds(prodIds);
    }
}
